<template>
  <view class="login-container pageBg">
    <view class="login-card">
      <view class="logo-area">
        <image class="logo" src="@/static/logo.png" mode="aspectFit" />
      </view>
      <view class="title">河南农业大学AI应用广场</view>
      <view class="qr-container">
        <view class="qr-title">
          <uni-icons type="scan" size="20" color="#666666" />
          <text class="qr-text">使用本人的微信扫码授权登录</text>
        </view>
        <view class="qr-code">
          	<iframe v-if="!is_wx" class="login-iframe" :src="jump_url"  style="height: 600rpx; width: 600rpx;"/>
        </view>
      </view>
      <view class="tips">
        <text class="tips-text">请确保使用本人微信账号扫码登录</text>
      </view>
    </view>
  </view>
</template>

<script lang="ts" setup>
import { ref,onMounted } from "vue";

// 微信ua检测
const is_wx = ref(navigator.userAgent.toLowerCase().includes("micromessenger"));
const APPID = "ndd956a392c8b55d39";
//const APPID = "nd1e1228b7e91cfda0";
const WEBURL = location.origin + "/#/";
const redirectUrl = encodeURIComponent(WEBURL + "pages/menu/index");
const jump_url = ref(`https://oauth.henau.edu.cn/oauth2_qr_connect/login?appid=${APPID}&redirect_uri=${redirectUrl}&response_type=code&scope=henauapi_login&hidetips=true`);

function wechatLogin() {
	window.location.href = jump_url.value;
}

// 在微信环境下自动登录
onMounted(() => {
	if (is_wx.value) {
		wechatLogin();
	}
});

const logoUrl =
  "https://public.readdy.ai/ai/img_res/573ef875a2f42b9a0865e637ee867f05.jpg";
</script>

<style>
page {
  height: 100%;
}

.login-container {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 680rpx;
  background-color: rgba(255, 255, 255, 0.6);
  border-radius: 24rpx;
  box-shadow: 0 8rpx 30rpx rgba(0, 0, 0, 0.08);
  padding: 60rpx 48rpx;
  transition: all 0.3s ease;
}

.logo-area {
  display: flex;
  justify-content: center;
  margin-bottom: 40rpx;
}

.logo {
  width: 120rpx;
  height: 120rpx;
  border-radius: 24rpx;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
}

.title {
  font-size: 42rpx;
  color: #333333;
  font-weight: bold;
  text-align: center;
  margin-bottom: 60rpx;
  letter-spacing: 2rpx;
}

.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: #f9fafc;
  padding: 30rpx;
  border-radius: 16rpx;
}

.qr-title {
  display: flex;
  align-items: center;
  margin-bottom: 36rpx;
  background-color: #eef2ff;
  padding: 16rpx 24rpx;
  border-radius: 40rpx;
}

.qr-text {
  font-size: 28rpx;
  color: #4a5568;
  margin-left: 12rpx;
  font-weight: 500;
}

.qr-code {
  position: relative;
  background-color: #ffffff;
  border-radius: 16rpx;
  overflow: hidden;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
  border: 4rpx solid #eef2ff;
}

.qr-image {
  width: 100%;
  height: 100%;
}

.loading-mask,
.expired-mask {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.loading-text,
.expired-text {
  font-size: 28rpx;
  color: #4a5568;
  margin-top: 24rpx;
  font-weight: 500;
}

.tips {
  margin-top: 48rpx;
  text-align: center;
  background-color: #fff8e6;
  padding: 16rpx 24rpx;
  border-radius: 12rpx;
  border-left: 6rpx solid #ffc107;
}

.tips-text {
  font-size: 26rpx;
  color: #755600;
}

.login-iframe {
  border: none;
  border-radius: 16rpx;
}
</style>
